function colorString2Hex(color: string): [number, number, number] {
  const hex = color.replace("#", "");
  return [
    parseInt(hex.substring(0, 2), 16),
    parseInt(hex.substring(2, 4), 16),
    parseInt(hex.substring(4, 6), 16),
  ];
}

export function generateColorStep(
  startColor: string,
  endColor: string,
  step: number
): string[] {
  if (step < 1) {
    return [];
  } else if (step === 1) {
    return [startColor];
  }

  const start = colorString2Hex(startColor);
  const end = colorString2Hex(endColor);
  const rt = end[0] - start[0];
  const gt = end[1] - start[1];
  const bt = end[2] - start[2];

  const colors = [];
  for (let i = 0; i < step; i++) {
    const r = Math.round(start[0] + (rt * i) / (step - 1));
    const g = Math.round(start[1] + (gt * i) / (step - 1));
    const b = Math.round(start[2] + (bt * i) / (step - 1));
    const colorNum = `${r.toString(16)}${g.toString(16)}${b.toString(16)}`.padStart(6, '0');
    colors.push(`#${colorNum}`);
  }
  //console.log(colors);
  return colors;
}

export function generateRandomColors(num:number): string[] {
    const colors = new Array<string>(num);
    for (let i = 0; i < num; i++) 
      colors[i] = `#${Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, '0')}`;
    return colors;
}